#define _CRT_SECURE_NO_WARNINGS 1

class Solution {
public:
    int maxProfit(vector<int>& prices) {
        int lowprices = prices[0];
        int hightprofit = 0;
        for (int i = 1; i < prices.size(); i++)
        {
            if (prices[i] < lowprices)
            {
                lowprices = prices[i];
            }
            else {
                int profit = prices[i] - lowprices;
                if (profit > hightprofit)
                {
                    hightprofit = profit;
                }
            }
        }
        return hightprofit;
    }
};